#!/bin/bash
source /etc/profile

start () {
    cd /data/htdocs/prometheus/
    ./prometheus --config.file=prometheus.yml --web.external-url=prome > /data/logs/prometheus.log 2>&1 &
    sleep 3
    [ -n $(ps aux|grep prometheus|grep config|grep -v grep|awk '{print $2}') ] && echo "start prometheus success"
}

stop () {
    prometheus_pid=$(ps aux|grep prometheus|grep config|grep -v grep|awk '{print $2}')
    kill -9 ${prometheus_pid}
    echo "stop prometheus success"
}

case $1 in
    start)
        start;;
    stop)
        stop;;
    restart)
        stop
        sleep 2
        start;;
    *)
        echo "Usage: ./prometheus start|stop|restart";;
esac
